package db

import (
    "fmt"

    "xlib/log"

    //mysql drivers
    _ "github.com/go-sql-driver/mysql"
    "github.com/go-xorm/core"
    "github.com/go-xorm/xorm"
)

var engine *xorm.Engine

//MkDbConn 连接数据库
func MkDbConn(driver string, dataSource string) error {
    log.Info("make database connection.")
    eng, err := xorm.NewEngine(driver, dataSource)
    if err != nil {
        return err
    }
    engine = eng
    engine.SetMapper(core.GonicMapper{})

    return nil
}

//GetConn 获取数据库连接
func GetConn(driver string, dataSource string) *xorm.Engine {
    fmt.Println(driver, dataSource)
    return engine
}
